package com.xhs.main.controller.yfb;

import com.xhs.main.entity.result.LayuiResponseResult;
import com.xhs.main.entity.rsb.RsbUser;
import com.xhs.main.entity.yfb.YfbGroup;
import com.xhs.main.service.rsb.RsbUserService;
import com.xhs.main.service.yfb.YfbGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @create 2020-10-20 9:49
 */
@RestController  //复合主键。便是整个类都使用异步
public class GroupController {
    @Autowired
    YfbGroupService yfbGroupService;

    @Autowired
    RsbUserService rsbUserService;

    //查询所有的分组信息
    @RequestMapping("/yfb/groups")
    public LayuiResponseResult allGroup() {
        List<YfbGroup> yfbGroups = yfbGroupService.allGroups();
        return new LayuiResponseResult(0, "", yfbGroups.size(), yfbGroups);
    }

    //查询不同分类（软件/硬件）的分组信息,
    @RequestMapping("/yfb/groupByClass")
    public LayuiResponseResult groupByClass(String yfbRespClass) {
        //返回的是分组后的所有组员信息
        List<YfbGroup> yfbGroups = yfbGroupService.queryGroupByClass(yfbRespClass);
        return new LayuiResponseResult(0, "", yfbGroups.size(), yfbGroups);

    }

    //添加小组成员
    @RequestMapping("/yfb/addGroup")
    public LayuiResponseResult addGroup(YfbGroup yfbGroup) {
        yfbGroupService.addGroup(yfbGroup);
        return new LayuiResponseResult(0, "", null, null);
    }

    //删除小组成员
    @RequestMapping("/yfb/deleteGroup")
    public LayuiResponseResult deleteGroup(Integer primaryKey) {
        yfbGroupService.deleteGroupByParentId(primaryKey);
        return new LayuiResponseResult(0, "", null, null);
    }

    //查询员工--参数：职位：userPost，分页：page，size
    @RequestMapping("/yfb/queryEmployees")
    public LayuiResponseResult queryEmpByPosition(String userPost, Integer page, Integer limit) {
        //layui默认分页使用page和limit参数表示分页数据。
        RsbUser user = new RsbUser();
        user.setUserPost(userPost + "工程师");
        List<RsbUser> rsbUsers = rsbUserService.selectUserByChoose(user);
        List<RsbUser> rsbUsersLimit = rsbUserService.selectUserByChooseLimit(user, (page - 1) * limit, limit);
        return new LayuiResponseResult(0, "", rsbUsers.size(), rsbUsersLimit);
    }


}
